<?php
namespace app\index\controller;

use app\index\model\AccountListModel;
use app\index\model\AccountModel;
use app\index\model\ArchiveModel;
use app\index\model\BidModel;
use app\index\model\CertCompanyModel;
use app\index\model\CertModel;
use app\index\model\CertPersonModel;
use app\index\model\CertUseBidListModel;
use app\index\model\CertUseBidModel;
use app\index\model\CertUseListModel;
use app\index\model\CertUseModel;
use app\index\model\ContractBuModel;
use app\index\model\ContractCaiListModel;
use app\index\model\ContractCaiModel;
use app\index\model\ContractNeiListModel;
use app\index\model\ContractNeiModel;
use app\index\model\ContractShiGongModel;
use app\index\model\ContractShiModel;
use app\index\model\ContractYangModel;
use app\index\model\DangJieListModel;
use app\index\model\DangModel;
use app\index\model\DealcomModel;
use app\index\model\DeptModel;
use app\index\model\DeviceJieListModel;
use app\index\model\DeviceJieModel;
use app\index\model\DeviceJinListModel;
use app\index\model\DeviceLinModel;
use app\index\model\DeviceTuiModel;
use app\index\model\DeviceYunModel;
use app\index\model\EnginBondShouModel;
use app\index\model\EnginBudgetListModel;
use app\index\model\EnginBudgetModel;
use app\index\model\EnginBudshouModel;
use app\index\model\EnginBudsubModel;
use app\index\model\EnginChanModel;
use app\index\model\EnginJianModel;
use app\index\model\EnginModel;
use app\index\model\EnginSpeedListModel;
use app\index\model\EnginXunListModel;
use app\index\model\EnginXunModel;
use app\index\model\FileModel;
use app\index\model\FlowBillModel;
use app\index\model\FlowLogModel;
use app\index\model\FlowNodeModel;
use app\index\model\FlowTalkModel;
use app\index\model\FlowTaskModel;
use app\index\model\FlowUsedModel;
use app\index\model\IncomeEnginModel;
use app\index\model\IncomeHuanModel;
use app\index\model\LabourBanModel;
use app\index\model\LabourGongModel;
use app\index\model\LabourHuaModel;
use app\index\model\LabourJieModel;
use app\index\model\LabourLingModel;
use app\index\model\LabourShenListModel;
use app\index\model\LabourShenModel;
use app\index\model\LabourXiangModel;
use app\index\model\LabourYongModel;
use app\index\model\OptionModel;
use app\index\model\PaymentBaoModel;
use app\index\model\PaymentGongModel;
use app\index\model\PaymentJieModel;
use app\index\model\PaymentNeikouListModel;
use app\index\model\PiaokaiModel;
use app\index\model\ReadsModel;
use app\index\model\SealModel;
use app\index\model\SpeedMonthListModel;
use app\index\model\SpeedMonthModel;
use app\index\model\SpeedZongListModel;
use app\index\model\SpeedZongModel;
use app\index\model\StuffCaiListModel;
use app\index\model\StuffCaiModel;
use app\index\model\StuffChuModel;
use app\index\model\StuffJieListModel;
use app\index\model\StuffJieModel;
use app\index\model\StuffRuListModel;
use app\index\model\StuffRuModel;
use app\index\model\StuffTuiModel;
use app\index\model\SubbaoJieModel;
use app\index\model\SubbaoShenListModel;
use app\index\model\SubbaoShenModel;
use app\index\model\TodoModel;
use app\index\model\UserGangModel;
use app\index\model\UserModel;
use app\index\model\VisaModel;
use app\index\model\WenBanModel;
use app\index\model\WenFaModel;
use app\index\model\WenShouModel;
use app\index\model\WuCaiListModel;
use app\index\model\WuCaiModel;
use app\index\model\WuChuModel;
use app\index\model\WuLingListModel;
use app\index\model\WuRuListModel;
use app\index\service\BidService;
use app\index\service\BudgetService;
use app\index\service\CertService;
use app\index\service\ContractService;
use app\index\service\EnginService;
use app\index\service\FlowService;
use app\index\service\LabourService;
use app\index\service\MenuService;
use app\index\service\OptService;
use app\index\service\PaymentService;
use app\index\service\PiaoService;
use app\index\service\UserService;
use think\Db;
use think\Request;

class Opt extends Common
{

    public function get_readsandlog(Request $request){
        $param = $request->post();
        if(!isset($param['table']) || empty($param['table'])){
            return outputJson(2000, lang('code_2000'), []);
        }
        if(!isset($param['mid']) || empty($param['mid'])){
            return outputJson(2000, lang('code_2000'), []);
        }

        $shuju = Db::name($param['table'])->where(['id'=>$param['mid']])->find();
        if(!$shuju){
            return outputJson(2000, lang('code_2000'), []);
        }

        $dataDelStr = '';
        if(isset($shuju['deleted_user']) && $shuju['deleted_user'] > 0){
            $delUser = UserModel::where(['id'=>$shuju['deleted_user']])->value('realname');
            $delTime = '';
            if($shuju['deleted_at'] && $shuju['deleted_at'] != '0000-00-00 00:00:00'){
                $delTime = date("Y年m月d日 H时i分", strtotime($shuju['deleted_at']));
            }
            $dataDelStr = "当前数据已被【".$delUser." ".$delTime."】删除";
        }



        try {
            TodoModel::where(['uid'=>$this->userinfo['id'],'table'=>$param['table'],'mid'=>$param['mid'],'status'=>0])->update([
                'status'=>1,'readdt'=>date("Y-m-d H:i:s")
            ]);

            $flowlog = FlowLogModel::where(['table'=>$param['table'],'mid'=>$param['mid']])->select()->toArray();
            foreach ($flowlog as &$item){
                $user = UserModel::field('realname,avatar')->where(['id'=>$item['created_user']])->find();
                $item['created_user'] = $user['realname'];
                $item['avatar'] = $user['avatar'];
            }

            $readsModel = new ReadsModel();
            $info = $readsModel->where(['table'=>$param['table'],'mid'=>$param['mid'],'optid'=>$this->userinfo['id']])->find();
            if($info){
                $info->optdt = date('Y-m-d H:i:s');
                $info->stotal = $info['stotal'] + 1;
                $info->save();
            }else{
                $readsModel->add_reads($param['table'], $param['mid'], $this->userinfo['id'],$this->userinfo['comid']);
            }
            $reads = $readsModel->alias('r')->field('r.stotal,r.optdt,u.realname,u.avatar')
                ->join('user u','u.id=r.optid')
                ->where(['table'=>$param['table'],'mid' => $param['mid']])->select()->toArray();
        } catch (\Exception $e) {
            return outputJson(2000, lang('code_2000'), []);
        }
        return outputJson(2000, lang('code_2000'), [
            'dataDelStr' => $dataDelStr,
            'flowlog' => $flowlog,
            'reads' => $reads,
        ]);
    }

    public function get_flowtalk(Request $request){
        $param = $request->post();
        $data = FlowTalkModel::where(['comid'=>$this->userinfo['comid'],'billid'=>$param['id']])->select()->toArray();
        foreach ($data as &$item){
            $item['domer_name'] = UserModel::get_realname_by_ids($item['domer']);

            $uidinfo = UserModel::field('realname,avatar')->where(['id'=>$item['uid']])->find();
            $item['uid_name'] = $uidinfo['realname'];
            $item['uid_avatar'] = $uidinfo['avatar'];

            $item['filesarr'] = FileModel::field('id,table,mid,name,ext,size,encpath,fileplain,created_user,created_at')
                ->where('id','in',$item['files'])->select()->toArray();
        }
        return outputJson(2000, lang('code_2000'), $data);
    }


    public function get_userpart(Request $request){
        $keyword = $request->param('keyword', '', 'string');
        $type = $request->param('type', 'user', 'string');
        $dept = $request->param('dept', '', 'string');

        $where = [];
        if($dept == 'chan'){
            $where[] = ['type', '=', 2];
        }
        if($type == 'dept'){
            $where[] = ['name','like','%'.$keyword.'%'];
        }

        $whereUser = [];
        if($type == 'user'){
            $whereUser[] = ['realname','like','%'.$keyword.'%'];
        }
        $data = DeptModel::where(['status'=>1,'deleted_user'=>0])->where($where)->field('id,pid,name as title,sort')->select()->toArray();
        foreach ($data as &$item){
            $item['basicData'] = ['id'=>$item['id'],'name'=>$item['title'],'part'=>'dept'];
            $item['children'] = [];

            if($type == 'user' || $type == 'part'){
                $users = UserModel::where(['deleted_user'=>0,'status'=>1,'deptid'=>$item['id']])->where($whereUser)
                    ->field('id,realname as title')->select()->toArray();
                foreach ($users as &$user){
                    $user['sort'] = 0;
                    $user['basicData'] = ['id'=>$user['id'],'name'=>$user['title'],'part'=>'user'];
                    $user['name'] = $user['title'];
                    $user['title'] = '&nbsp;&nbsp;<i class="layui-icon layui-icon-username"></i>&nbsp;&nbsp;'.$user['title'];
                }
                $item['children'] = $users;
            }

            if(count($item['children']) > 0){
                $item['title'] = '<i class="layui-icon layui-icon-template"></i>&nbsp;&nbsp;'.$item['title'];
            }else{
                $item['title'] = '&nbsp;&nbsp;<i class="layui-icon layui-icon-template"></i>&nbsp;&nbsp;'.$item['title'];
            }

        }



        $data = array2tree($data, 'id', 'pid','children','sort');
        return json_encode([
            'status'=>['code'=>200,'message'=>"操作成功"],
            'data'=>$data,
            'code'=>2000,
            'msg'=>'请求成功',
        ]);
    }



    // 部门人员
    public function get_dept_user(){
        $input = input('post.');
        $where = [];
        if(isset($input['keyword']) && !empty($input['keyword'])){
            $where[] = ['realname','like','%'.$input['keyword'].'%'];
        }

        $data = DeptModel::where(['status'=>1,'deleted_user'=>0])->field('id,pid,name as title')->select()->toArray();
        foreach ($data as &$item){
            $rawWhere = Db::raw("find_in_set(".$item['id'].",deptid)");
            $users = UserModel::where($rawWhere)->where(['deleted_user'=>0,'status'=>1])->where($where)->field('id,realname as title')->select()->toArray();
            foreach ($users as &$user){
                $user['name'] = $user['title'];
                $user['title'] = '&nbsp;&nbsp;<i class="layui-icon layui-icon-username"></i>&nbsp;&nbsp;'.$user['title'];
            }
            $item['children'] = $users;

            if(count($item['children']) > 0){
                if(isset($input['keyword']) && !empty($input['keyword'])){
                    $item['spread'] = true;
                }
                $item['title'] = '<i class="layui-icon layui-icon-template"></i>&nbsp;&nbsp;'.$item['title'];
            }else{
                $item['title'] = '&nbsp;&nbsp;<i class="layui-icon layui-icon-template"></i>&nbsp;&nbsp;'.$item['title'];
            }
        }

        $data = array2tree($data);
        return outputJson(2000,lang('code_2000'),$data);
    }

    // 部门
    public function get_dept(){
        $input = input('post.');
        $where = [];
        if(isset($input['keyword']) && !empty($input['keyword'])){
            $where[] = ['name','like','%'.$input['keyword'].'%'];
        }
        $data = DeptModel::where(['status'=>1,'deleted_user'=>0])->where($where)->field('id,pid,name')->select()->toArray();
        foreach ($data as &$item){
            $item['title'] = $item['name'];
//            $item['title'] = '<i class="layui-icon layui-icon-template"></i>&nbsp;&nbsp;'.$item['name'];
        }
        $data = array2tree($data);
        return outputJson(2000,lang('code_2000'),$data);

    }


    public function get_dealcom(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['deal.deleted_user','=', 0];
        $where[] = ['deal.comid','=',$this->userinfo['comid']];

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['deal.name|deal.lianer|deal.liantel','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['name']) && !empty($param['name'])){
            $where[] = ['deal.name','like', '%'.$param['name'].'%'];
        }
        if(isset($param['type']) && !empty($param['type'])){
            $where[] = ['deal.type','=', $param['type']];
        }
        if(isset($param['lianer']) && !empty($param['lianer'])){
            $where[] = ['deal.lianer','like', '%'.$param['lianer'].'%'];
        }
        if(isset($param['liantel']) && !empty($param['liantel'])){
            $where[] = ['deal.liantel','like', '%'.$param['liantel'].'%'];
        }

        $data['type'] = (new EnginService())->get_dealcom_type();
        $data['is_type'] = isset($param['type']) ? $param['type'] : '';



        $data['data'] = DealcomModel::alias('deal')
            ->field('deal.*')
            ->where($where)
            ->order('deal.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['type'] = (new EnginService())->get_dealcom_type_name($item['type']);
                return $item;
            })->toArray();

        return outputJson(2000,lang('code_2000'),$data);
    }

    public function get_engin(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['e.deleted_user','=', 0];
        $where[] = ['e.comid','=',$this->userinfo['comid']];
        $where[] = ['e.isturn','=',1];
        $where[] = ['e.status','=',1];


        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['e.name','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['business']) && !empty($param['business'])){
            $where[] = ['e.business','=', $param['business']];
        }
        if(isset($param['lian_unit']) && !empty($param['lian_unit'])){
            $where[] = ['e.lian_unit','like', '%'.$param['lian_unit'].'%'];
        }
        if(isset($param['name']) && !empty($param['name'])){
            $where[] = ['e.name','like', '%'.$param['name'].'%'];
        }
        if(isset($param['number']) && !empty($param['number'])){
            $where[] = ['e.number','like', '%'.$param['number'].'%'];
        }
        if(isset($param['engintype']) && !empty($param['engintype'])){
            $where[] = ['e.engintype','=', $param['engintype']];
        }
        if(isset($param['jian_unit']) && !empty($param['jian_unit'])){
            $where[] = ['e.jian_unit','like', '%'.$param['jian_unit'].'%'];
        }
        if(isset($param['areas']) && !empty($param['areas'])){
            $where[] = ['e.areas','like', '%'.$param['areas'].'%'];
        }
        if(isset($param['addr']) && !empty($param['addr'])){
            $where[] = ['e.addr','like', '%'.$param['addr'].'%'];
        }
        if(isset($param['expectfee']) && !empty($param['expectfee'])){
            $where[] = ['e.expectfee','like', '%'.$param['expectfee'].'%'];
        }
        if(isset($param['duration']) && !empty($param['duration'])){
            $where[] = ['e.duration','like', '%'.$param['duration'].'%'];
        }
        if(isset($param['startdt']) && !empty($param['startdt'])){
            $where[] = ['e.startdt','between', explode(' - ', $param['startdt'])];
        }
        if(isset($param['enddt']) && !empty($param['enddt'])){
            $where[] = ['e.enddt','between', explode(' - ', $param['enddt'])];
        }
        if(isset($param['state']) && $param['state'] != ''){
            $where[] = ['e.state','=', $param['state']];
        }
        if(isset($param['zhaotype']) && !empty($param['zhaotype'])){
            $where[] = ['e.zhaotype','=', $param['zhaotype']];
        }
        if(isset($param['actualdt']) && !empty($param['actualdt'])){
            $where[] = ['e.actualdt','between', explode(' - ', $param['actualdt'])];
        }
        if(isset($param['filishdt']) && !empty($param['filishdt'])){
            $where[] = ['e.filishdt','between', explode(' - ', $param['filishdt'])];
        }


        $state = (new EnginService())->get_engin_state();
        $data['state'] = $state;
        $data['is_state'] = isset($param['state']) ? $param['state'] : '';

        $data['engintype'] = (new OptService())->get_base_info('engin_engintype');
        $data['is_engintype'] = isset($param['engintype']) ? $param['engintype'] : '';

        $data['zhaotype'] = (new OptService())->get_base_info('bid_bidding_type');
        $data['is_zhaotype'] = isset($param['zhaotype']) ? $param['zhaotype'] : '';


        $data['data'] = EnginModel::alias('e')
            ->field('e.*')
            ->where($where)
            ->where((new MenuService())->get_opt_where('engin', 'e'))
            ->order('e.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['hanghao'] = $key+1;
                $item['yearcur'] = date('Y');
                $item['chanid_name'] = DeptModel::get_name_by_pk($item['chanid']);
                $item['man_xiang_name'] = UserModel::get_realname_by_pk($item['man_xiang']);
                $item['man_xiang_tel'] = UserModel::where(['id'=>$item['man_xiang']])->value('tel');
                $item['business_name'] = $item['business'] == 1 ? '自营' : '联营';
                $item['state_name'] = (new EnginService())->get_engin_state_name_tag($item['id'], $item['state']);
                $item['isting'] = $item['state'] == 3 ? true : false;

                $item['engintype_old'] = $item['engintype'];
                $item['engintype'] = (new OptService())->get_base_showname('engin_engintype', $item['engintype']);
                $item['zhaotype'] = (new OptService())->get_base_showname('bid_bidding_type', $item['zhaotype']);

                $item['budgetid'] = EnginBudgetModel::where(['enginid'=>$item['id'],'deleted_user'=>0,'isturn'=>1,'status'=>1])->value('id');

                //施工合同名称
                $item['shiid'] = ContractShiModel::where(['comid'=>$this->userinfo['comid'],'enginid'=>$item['id'],'deleted_user'=>0,'isturn'=>1])
                    ->where('status','in',[0,1])->value('id');
                $item['shiname'] = ContractShiModel::where(['comid'=>$this->userinfo['comid'],'enginid'=>$item['id'],'deleted_user'=>0,'isturn'=>1])
                    ->where('status','in',[0,1])->value('name');
                $item['shifaer'] = ContractShiModel::where(['comid'=>$this->userinfo['comid'],'enginid'=>$item['id'],'deleted_user'=>0,'isturn'=>1])
                    ->where('status','in',[0,1])->value('faer');
                $item['shichenger'] = ContractShiModel::where(['comid'=>$this->userinfo['comid'],'enginid'=>$item['id'],'deleted_user'=>0,'isturn'=>1])
                    ->where('status','in',[0,1])->value('chenger');
                $item['shichenger_name'] = DeptModel::get_name_by_pk($item['shichenger']);

                $cert_use = [];
                $useArr = CertUseModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'isturn'=>1,'status'=>1,'isreal'=>1,'enginid'=>$item['id']])->find();
                if($useArr){
                    $certuselist = CertUseListModel::where(['useid'=>$useArr['id']])->select()->toArray();
                    foreach ($certuselist as $vvv){
                        $certInfo = CertModel::where(['id'=>$vvv['certid']])->find();
                        $vvv['name'] = $certInfo['name'];
                        $vvv['number'] = $certInfo['number'];
                        $vvv['major_name'] = str_replace('[]', ',', $certInfo['major']);
                        $vvv['person_name'] = CertPersonModel::where(['id'=>$certInfo['personid']])->value('name');
                        $vvv['statueuse_name'] = (new CertService())->get_cert_statueuse_name($certInfo['statueuse']);
                        $vvv['chanid_name'] = DeptModel::get_name_by_pk($certInfo['chanid']);
                        $cert_use[] = $vvv;
                    }
                }
                $item['cert_use'] = $cert_use;


                $item['jian_unitinfo'] = DealcomModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'isturn'=>1,'status'=>1,'name'=>$item['jian_unit']])->find();


                return $item;
            })->toArray();
        return outputJson(2000,lang('code_2000'),$data);
    }







    public function get_flowrelas(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['bill.deleted_user','=', 0];
        $where[] = ['bill.comid','=',$this->userinfo['comid']];
        $where[] = ['bill.created_user','=',$this->userinfo['id']];
        $where[] = ['bill.isturn','=', 1];
        $where[] = ['bill.status','=', 1];


        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['bill.sericnum|bill.summary|bill.enginame','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['sericnum']) && !empty($param['sericnum'])){
            $where[] = ['bill.sericnum','like', '%'.$param['sericnum'].'%'];
        }
        if(isset($param['summary']) && !empty($param['summary'])){
            $where[] = ['bill.summary','like', '%'.$param['summary'].'%'];
        }
        if(isset($param['enginame']) && !empty($param['enginame'])){
            $where[] = ['bill.enginame','like', '%'.$param['enginame'].'%'];
        }
        if(isset($param['modeid']) && !empty($param['modeid'])){
            $where[] = ['bill.modeid','=', $param['modeid']];
        }
        if(isset($param['created_at']) && !empty($param['created_at'])){
            $seadt = explode(' - ', $param['created_at']);
            $where[] = ['bill.created_at','between', [$seadt[0].' 00:00:00', $seadt[1].' 23:59:59']];
        }


        $data['data'] = FlowBillModel::alias('bill')
            ->field('bill.*')
            ->where($where)
            ->order('bill.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
//                $item['status_name'] = (new FlowService())->get_flow_flowtext($item);
                return $item;
            })->toArray();



        $data['modeidArr'] = (new FlowService())->get_flow_modename();
        $data['is_modeid'] = isset($param['modeid']) ? $param['modeid'] : '';
        return outputJson(2000,lang('code_2000'),$data);
    }



    public function get_flow_used(Request $request){
        $data = FlowUsedModel::where(['comid'=>$this->userinfo['comid'],'uid'=>$this->userinfo['id']])->select()->toArray();
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_flow_used(Request $request){
        $explain = $request->param('explain', '', 'string');

        if(empty($explain)){
            return outputJson(4000,lang('code_4000'));
        }

        FlowUsedModel::insertGetId([
            'comid' => $this->userinfo['comid'],
            'uid' => $this->userinfo['id'],
            'explain' => $explain,
        ]);

        $data = FlowUsedModel::where(['comid'=>$this->userinfo['comid'],'uid'=>$this->userinfo['id']])->select()->toArray();
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function del_flow_used(Request $request){
        $id = $request->param('id', 0, 'int');
        FlowUsedModel::where(['comid'=>$this->userinfo['comid'],'uid'=>$this->userinfo['id'],'id'=>$id])->delete();
        $data = FlowUsedModel::where(['comid'=>$this->userinfo['comid'],'uid'=>$this->userinfo['id']])->select()->toArray();
        return outputJson(2000,lang('code_2000'),$data);
    }


    public function get_flow_tui_info(Request $request){
        $param = $request->post();
        $bill = FlowBillModel::where(['comid'=>$this->userinfo['comid'],'id'=>$param['id']])->find();
        if(!$bill){
            return outputJson(4000, "无法退回");
        }
        if($bill['isturn'] != 1){
            return outputJson(4000, "无法退回");
        }
        if($bill['status'] != 0){
            return outputJson(4000, "无法退回");
        }

        $minfo = Db::name($bill['modenum'])->where(['id'=>$bill['mid']])->find();
        if(!$minfo){
            return outputJson(4000, "无法退回");
        }

        $myTask = FlowTaskModel::where(['comid'=>$this->userinfo['comid'],'billid'=>$bill['id'],'state'=>1])
            ->where(['uid'=>$this->userinfo['id'],'deleted_user'=>0])->find();
        if(!$myTask){
            return outputJson(4000, "无法退回");
        }

        $node = FlowNodeModel::where(['id'=>$myTask['nodeid']])->find();
        if(!$node){
            return outputJson(4000, "无法退回");
        }

        $listJie = FlowNodeModel::field('id,name')->where(['comid'=>$this->userinfo['comid'],'billid'=>$bill['id']])
            ->where('id','lt', $node['id'])->order('id DESC')->select()->toArray();

        $listRen = [];
        foreach ($listJie as $k=>$v){
            $sontask = FlowTaskModel::field('id,inituid')->where(['comid'=>$this->userinfo['comid'],'billid'=>$bill['id'],'nodeid'=>$v['id'],'pid'=>0,'state'=>2])
                ->order('id DESC')->select()->toArray();
            if($sontask){
                foreach ($sontask as $kk=>$vv){
                    $inituid_name = UserModel::get_realname_by_pk($vv['inituid']);
                    $listRen[] = ['id'=>$vv['id'], 'name'=>$v['name'].'：'.$inituid_name];
                }
            }
        }

        $listJie[] = ['id'=>0, 'name'=>'申请人发起申请'];

        if($node['type'] == 2){
            $listJie = [['id'=>0, 'name'=>'申请人发起申请']];
        }

        $data['listJie'] = $listJie;
        $data['listRen'] = $listRen;
        $data['nodetype'] = $node['type'];
        return outputJson(2000,lang('code_2000'),$data);
    }



}





















